﻿/// <reference path="../ext-all.js" />

//自动选用Ext或者JQ进行通信
(function () {
    this.appendMyAjax = function () {
        var me = this;
        if (typeof (MyAjax) != "undefined") {
            MyAjax.post = function (sUrl, sPostData, bAsync, oCallBackFunction, aCallBackFunctionParameters) {
                return me.callServer(sUrl, sPostData, bAsync, "POST", oCallBackFunction, aCallBackFunctionParameters);
            };
            MyAjax.get = function (sUrl, vParam, bAsync, oCallBackFunction, aCallBackFunctionParameters) {
                return me.callServer(sUrl, vParam, bAsync, "GET", oCallBackFunction, aCallBackFunctionParameters);
            };
            this.callServer = function (sUrl, vData, bAsync, sType, oCallBackFunction, aCallBackFunctionParameters) {
                if (typeof (bAsync) == "undefined" || bAsync == null) bAsync = false; //默认采用同步的模式通信
                var sResult;
                jQuery.ajax({
                    type: sType,
                    url: sUrl,
                    async: bAsync,
                    data: vData,
                    success: function (data, textStatus) {
                        sResult = data;
                        if (oCallBackFunction) {
                            oCallBackFunction(data, aCallBackFunctionParameters);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        //alert(errorThrown);
                    }
                });
                return sResult;
            };
        }
        else {
            window.setTimeout("this.appendMyAjax()()", 100);
        }
    }
    this.appendMyAjax();
})();
